import Helper
import sys
import UAI
import pygame
import Debug

class EventHandler:
    def onKey(self, key):
        if key == pygame.K_ESCAPE:
            sys.exit()
        elif key == pygame.K_SPACE:
            if UAI.PAUSE:
                UAI.PAUSE = False
            else:
                UAI.PAUSE = True
        elif key == pygame.K_BACKSPACE:
            for item in UAI.game.getMovableItems():
                item.targets = []
            
    def handleEvents(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                self.onKey(event.key)
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    #left click
                    for item in UAI.game.getTeamMembers('Police'):
                        item.move(UAI.pathfinding.getClosestNode(event.pos))
                if event.button == 2:
                    # middle click
                    UAI.window.setColor((255,255,255))
                    if UAI.DEBUG:
                        UAI.pathfinding.drawGrid()
                if event.button == 3:
                    # right click
                    for item in UAI.game.getTeamMembers('Criminals'):
                        item.addTarget(UAI.pathfinding.getClosestNode(event.pos))
